/**
 * @class dfly.ModuleModel 
 */
dfly.ModuleModel = function(obj) {
   this.path = obj.path;
   this.parameters = obj.parameters;
   this.definition = obj.definition;
};


dfly.ModuleModel.init = function() {
   
   YAHOO.util.Connect.asyncRequest('POST', 'getModules.php', { success: function(o) {
      try {
         var modules = eval('('+o.responseText+')');
         dfly.modules = {};
         for(var i = 0 ; i < modules.length ; i++) {
            dfly.modules[modules[i].path] = modules[i];
         }
         
         // Create the window "addContainer"
         dfly.addContainerWindow = new dfly.windowAddContainer();
         
      }
      catch(ex) {
         console.log(ex);
      }
   } });
   
};


dfly.ModuleModel.get = function(path) {
   return new dfly.ModuleModel(dfly.modules[path]);
};

dfly.ModuleModel.getAllModules = function() {
   var a = [];
   for(var key in dfly.modules) {
      if(dfly.modules.hasOwnProperty(key)) {
         a.push(key);
      }
   }
   return a;
};


dfly.ModuleModel.prototype.save = function() {
   var postdata = "path="+this.path;
   postdata += "&parameters="+YAHOO.lang.JSON.stringify(this.parameters);
   if(this.definition) {
      postdata += "&definition="+YAHOO.lang.JSON.stringify(this.definition);
   }
   else {
      postdata += "&definition=";
   }
   YAHOO.util.Connect.asyncRequest('POST', 'save.php', { }, postdata);
};